package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.RoleAddDto;
import com.zzyl.dto.RolePageDto;
import com.zzyl.dto.RoleUpdateDto;
import com.zzyl.service.RoleService;
import com.zzyl.vo.RoleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
@Api(tags = "角色管理")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @PostMapping("/page/{pageNum}/{pageSize}")
    @ApiOperation("角色分页")
    public ResponseResult rolePage(@PathVariable Integer pageNum, @PathVariable Integer pageSize, @RequestBody RolePageDto dto) {
        PageResponse roleVos = roleService.rolePage(pageNum,pageSize,dto);
        return ResponseResult.success(roleVos);
    }

    @PutMapping
    @ApiOperation("角色添加")
    public ResponseResult addRole(@RequestBody RoleAddDto dto) {
        roleService.addRole(dto);
        return ResponseResult.success();
    }

    @DeleteMapping("/{roleIds}")
    @ApiOperation("删除角色")
    public ResponseResult deleteRole(@PathVariable String roleIds) {
        roleService.deleteRole(roleIds);
        return ResponseResult.success();
    }

    @GetMapping("/find-checked-resources/{roleId}")
    @ApiOperation("根据角色查询选中的资源数据")
    public ResponseResult<List<String>> findRoleCheckedResources(@PathVariable("roleId") Long roleId) {
        List<String> list= roleService.findRoleCheckedResources(roleId);
        return ResponseResult.success(list);
    }

    @PatchMapping
    @ApiOperation("角色修改")
    public ResponseResult updateRole(@RequestBody RoleUpdateDto dto) {
        roleService.updateRole(dto);
        return ResponseResult.success();
    }

    @PostMapping("/init-roles")
    @ApiOperation("角色下拉框")
    public ResponseResult getAllRoles() {
        List<RoleVo> roleVos = roleService.getAllRoles();
        return ResponseResult.success(roleVos);
    }




}
